package test1

import (
	"lifi"
	"lifi/plugins/transfers"
	"log"
	"time"
)

type Test1 struct {
	Name string
}

func (t Test1) Init() error {
	return nil
}

func (t Test1) Start(collector lifi.Collector) error {
	log.Printf("start test1 transfer\n")
	return nil
}

func (t Test1) Stop() {
	log.Printf("stop test1 transfer\n")
}

func (t Test1) Process(d lifi.Data, acc lifi.Collector) error {
	data, _ := d.(lifi.ByteData)
	log.Printf("process test1data:%s\n", data)

	tags := map[string]string{
		"groupid":  "1",
		"location": "test1",
	}
	fields := map[string]interface{}{
		"phase":   10.2,
		"voltage": 219,
		"current": 0.32,
	}
	nweData := lifi.NewMetricData("meters", "d001", tags, fields, time.Now())

	acc.Collect(nweData)
	return nil
}

var _ lifi.Transfer = &Test1{}

func init() {
	transfers.Add("test1", func() lifi.Transfer {
		return &Test1{}
	})
}
